// packageG/gratitudeAward/gratitudeAward.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: {},
    activeName: "first",
    dataList: [],
    isLoadMore: true,
    page: 1,
    titleName: "感恩奖"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdata();
  },
  initData(){
    this.setData({
      info: {},
      activeName: "first",
      dataList: [],
      isLoadMore: true,
      page: 1,
      titleName: "感恩奖"
    })
  },
  setTsLoadMore(bool){
    this.setData({
      isLoadMore:!bool
    })
  },
  getdata(){
    wx.showLoading({title: "加载中…"});
    let urlStr = app.getNetAddresss("plugin.distribution-appreciation.frontend.controllers.center.index");
    let json = {page:1};
    app._postNetWork({
      url: urlStr,
      data: json,
      success: ({data:{result,msg,data}}) => {
        wx.hideLoading();
        if(result){
          this.setData({
            info:data.info,
            dataList:data.list.data
          })
          this.setTsLoadMore(this.data.page == data.list.last_page);
          wx.setNavigationBarTitle({
            title: data.info.plugin_name || this.data.titleName
          })
        }else app.tips(msg)
      },
      fail: (res) => {
        wx.hideLoading()
      },
    });
  },
  getMoreData(){
    if(this.data.isLoadMore){
      let page = this.data.page + 1;
      this.setTsLoadMore(true);
      let urlStr = app.getNetAddresss("plugin.distribution-appreciation.frontend.controllers.center.index");
      app._postNetWork({
        url: urlStr,
        data: {page},
        success: ({data:{result,msg,data}}) => {
          if(result){
            let dataList = this.data.dataList.concat(data.list.data);
            this.setData({
              dataList,
              page
            })
            this.setTsLoadMore(this.data.page == data.list.last_page);
          }else app.tips(msg)
        },
        fail: (res) => {
          console.log(res);
        },
      });
    }else app.tips("没有更多数据了");
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})